import java.io.IOException;
import java.net.UnknownHostException;


public class CommunicationServeur extends Thread {
	TCP t;
	int monNumero;
	Position coup;
	
	public CommunicationServeur(int num,Position coup) throws UnknownHostException, IOException{
		t = new TCP("localhost", 5000);
		this.monNumero = num;
		this.coup = coup;
	}
	
		
	public synchronized void run(){
		
		String reponse;	
		try{
			t.openSession();
			System.out.println("je suis a la position "+Agent.getPosition().toString()+" et je veux aller a"+coup.toString() );
			t.ecrire(Agent.getPosition().toString());
			
			reponse = t.lire();
			if(reponse.equals("OK")){
				t.ecrire(coup.toString());
				reponse = t.lire();
				if(reponse.equals("OK")){
					Agent.setPosition(coup);
				}
			}
			else {
				System.out.println(reponse);
			}
			t.closeSession();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}	
	
}
